package com.xyoto.community.controller;

import com.xyoto.community.pojo.TransmissionEntity;
import com.xyoto.community.utils.Result;
import com.xyoto.community.webSocketServer.WebSocketServer;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author coderFu
 * @create 2022/2/19
 * 消息推送接口
 */

@RestController
@Api(value = "WebSocketController",tags = "消息推送接口")
@RequestMapping("/messagePush")
public class WebSocketController {

    @Autowired
    private WebSocketServer webSocketServer;

    @ApiOperation("向指定用户推送消息")
    @PostMapping("/sendMessageToOneUser")
    public Result sendMessageToOneUser(@RequestBody TransmissionEntity transmissionEntity){
        webSocketServer.sendMessageToUser(transmissionEntity,transmissionEntity.getUserId());
        return Result.success();
    }

    @ApiOperation("向所有用户推送消息")
    @PostMapping("/sendMessageToAll")
    public Result sendMessageToAll(@RequestBody TransmissionEntity transmissionEntity){
        webSocketServer.sendMessageToAll(transmissionEntity);
        return Result.success();
    }
}
